package com.sam.spring.chapter2;

import java.io.IOException;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sam.spring.chapter1.helloworld.HelloAPI;

public class AutowireBeanTest {
	@Test
	public void testAutowireByName() throws IOException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"chapter2/autowire-byName.xml");
		HelloAPI helloApi = context.getBean("bean", HelloAPI.class);
		helloApi.sayHello();
	}

	@Test
	public void testAutowireByType() throws IOException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"chapter2/autowire-byType.xml");
		HelloAPI helloApi = context.getBean("bean1", HelloAPI.class);
		helloApi.sayHello();

		helloApi = context.getBean("bean2", HelloAPI.class);
		helloApi.sayHello();
	}
	
	@Test
	public void testAutowireByConstructor() throws IOException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"chapter2/autowire-byConstructor.xml");
		HelloAPI helloApi = context.getBean("bean", HelloAPI.class);
		helloApi.sayHello();
	}
}
